<%--
  Created by IntelliJ IDEA.
  User: gongsir
  Date: 2020/8/20
  Time: 09:15
  显示当前登录用户基本资料
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    pageContext.setAttribute("path",request.getContextPath());
%>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${path}/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${path}/static/css/admin.css" media="all">
    <script type="text/javascript" src="${path}/static/layui/layui.all.js"></script>
</head>
<body>
<div class="layui-container layui-card">
    <div class="layui-fluid">
        <div class="layui-card-header">
            <h2>修改密码</h2>
        </div>
    </div>
    <div class="layui-fluid layui-card-body">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="username">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="username" placeholder="请输入用户名" required autocomplete="off" class="layui-input" value="${admin.username}" disabled>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="oldPass">原密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="oldPass" id="oldPass" placeholder="请输入原密码" required autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="password">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" id="password" placeholder="请输入密码" required autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1">
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="updatePass">提交</button>
                </div>
            </div>
            <!--
            <div class="layui-form-item layui-col-md-offset1">
                <div class="layui-input-inline">
                    <button type="button" id="btn_goBack" class="layui-btn layui-btn-fluid" onclick="goBack()">返回</button>
                </div>
            </div>
            -->
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form
            ,layer = layui.layer;

        //监听提交
        form.on('submit(updatePass)', function(data){
            console.log(data);
            layui.use('jquery',function(){
                var $=layui.$;
                $.ajax({
                    type: 'post',
                    url: '${path}/user/upPass', // ajax请求路径
                    dataType: 'json',
                    data: {
                        username:data.field.username,
                        oldPass:data.field.oldPass,
                        password:data.field.password
                    },
                    success: function(data){
                        console.log(data);
                        if(data.code === 100){
                            layer.alert(data.msg, { icon: 1, closeBtn: 0 }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.closeAll(index);
                                parent.location.href = 'http://localhost:8080';
                            });
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            });
            return false;//禁止跳转，否则会提交两次，且页面会刷新
        });
    });
    // 返回上一页
    function goBack(){
        window.history.go(-1);
    }
</script>
</body>
</html>
